module.exports = options => {
  return async function jwt(ctx, next) {
    const token = ctx.request.header.authorization;
    let decode='';
    if (token) {
      try {
        let tokens = token.replace('Bearer ', '');
        // 解码token
        decode = ctx.app.jwt.verify(tokens, options.secret);
        await next();
        // console.log(decode);
      } catch (error) {
        ctx.status = 200;
        ctx.body = {
          status: '1',
          msg: error.message,
          result: null
        };
        return
      }
    } else {
      ctx.status = 200;
      ctx.body = {
        status: '1',
        msg: '没有token',
        result: null
      }
      return
    }
    return decode;
  };
};
